<template>
  <div>
    <el-form ref="form" :rules="rules" :model="form" label-width="80px">
      <el-form-item label="题目" prop="topic_name">
        <el-input v-model="form.topic_name" size="small "></el-input>
      </el-form-item>
      <el-form-item label="来源" prop="topic_from">
        <el-select v-model="form.topic_from" placeholder="请选择来源">
          <el-option label="生产社会实际" value="生产社会实际"></el-option>
          <el-option label="应用科学技术" value="应用科学技术"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="类型" prop="topic_type">
        <el-select v-model="form.topic_type" placeholder="请选择类型">
          <el-option label="实践" value="实践"></el-option>
          <el-option label="应用" value="应用"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="难易程度" prop="topic_degree">
        <el-select v-model="form.topic_degree" placeholder="请选择">
          <el-option label="简单" value="简单"></el-option>
          <el-option label="适中" value="适中"></el-option>
          <el-option label="困难" value="困难"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="工作量" prop="topic_work">
        <el-select v-model="form.topic_work" placeholder="请选择">
          <el-option label="轻松" value="简单"></el-option>
          <el-option label="适中" value="适中"></el-option>
          <el-option label="困难" value="困难"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="可带学生" prop="allow_num">
        <el-input v-model="form.allow_num"></el-input>
      </el-form-item>
      <el-form-item label="条件具备" prop="topic_is">
        <el-select v-model="form.topic_is" placeholder="请选择">
          <el-option label="是" value="是"></el-option>
          <el-option label="否" value="否"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="课题内容" prop="topic_content">
        <el-input
          :rows="5"
          type="textarea"
          v-model="form.topic_content"
        ></el-input>
      </el-form-item>
      <el-form-item label="论文要求" prop="paper_requirement">
        <el-input
          :rows="5"
          type="textarea"
          v-model="form.paper_requirement"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即创建</el-button>
        <el-button @click="goback">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  data() {
    return {
      form: {},
      rules: {
        topic_name: [
          { required: true, message: "这是必填项", trigger: "blur" },
        ],
        topic_from: [
          { required: true, message: "这是必填项", trigger: "blur" },
        ],
        topic_type: [
          { required: true, message: "这是必填项", trigger: "blur" },
        ],
        topic_degree: [
          { required: true, message: "这是必填项", trigger: "blur" },
        ],
        topic_work: [
          { required: true, message: "这是必填项", trigger: "blur" },
        ],
        allow_num: [{ required: true, message: "这是必填项", trigger: "blur" }],
        topic_is: [{ required: true, message: "这是必填项", trigger: "blur" }],
        topic_content: [
          { required: true, message: "这是必填项", trigger: "blur" },
        ],
        paper_requirement: [
          { required: true, message: "这是必填项", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    goback() {
      this.$router.go(-1);
    },
    onSubmit() {
      this.$refs.form.validate((valid) => {
        if (!valid) return;
        this.$http
          .post(
            "http://127.0.0.1:8080/teacher/sendTopic",
            this.$qs.stringify(this.form)
          )
          .then((res) => {
            // console.log(res);
            this.$message.success("发送成功");
            this.form = "";
          });
      });
    },
  },
};
</script>
<style lang="less" scoped>
.el-input {
  width: 222px;
}
</style>
